{# SPDX-FileCopyrightText: © 2014-2017 Siemens AG

   SPDX-License-Identifier: FSFAP
#}
{% import "include/macros.html.twig" as macro %}

<form method="post" id="uiClearingForm">
  <input name="lastItem" id="lastItem" type="hidden" value="{{ itemId }}"/>
  <input name="upload" id="upload" type="hidden" value="{{ uploadId }}"/>
  <table>
    <tr>
      <td style="vertical-align:top;">
        <button type="submit" name="update" class="btn btn-default btn-sm" id="prev" disabled>&lt;</button>
        <button type="submit" name="update" class="btn btn-default btn-sm" onclick="form.action = '{{ uri }}&item={{ itemId }}';">{{ 'Submit'|trans }}</button>
        <button type="submit" name="update" class="btn btn-default btn-sm" id="next" disabled>&gt;</button>
      </td>
      <td>
        <input type="radio" class="info-bullet view-license-rc-size" name="FileSelection" value="none">
        {{ "Go through all files"|trans }}
        <img data-toggle="tooltip" data-placement="left" src="images/info_16.png" title="{{ 'Back and forward browsing through every file of the upload'|trans }}" alt="" class="info-bullet"/></img>
        <br/>
        <input type="radio" class="info-bullet view-license-rc-size" name="FileSelection" value="noLicense">
        {{ "Go through all files with licenses"|trans }}
        <img data-toggle="tooltip" data-placement="left" src="images/info_16.png" title="{{ 'Back and forward browsing going through files only with a license found by a scanner agent, regardless of an existing clearing result or not'|trans }}" alt="" class="info-bullet"/></img>
        <br/>
        <input type="radio" class="info-bullet view-license-rc-size" name="FileSelection" value="alreadyCleared">
        {{ "Go through all files with licenses and no clearing result"|trans }}
        <img data-toggle="tooltip" data-placement="left" src="images/info_16.png" title="{{ 'Back and forward browsing going through files only with a license found by a scanner agent only where no clearing result was created. This setting is useful for just browsing to “remaining work”'|trans }}" alt="" class="info-bullet"/>
      </td>
    </tr>
  </table>

  <div class="groupBox" style="display: flex; gap: 20px; align-items: flex-start;">
    <fieldset class="border p-2" style="display: inline;" {% if tmpClearingType %}class="border-danger"{% endif %} id="decTypeSet">
      <legend style="width:auto;">
        {{ 'Clearing decision type'| trans }}
      </legend>

      {% for typeKey, typeText in clearingTypes %}
        {% if typeKey == 5 %}
          <input type="radio" class="info-bullet view-license-rc-size" name="clearingTypes" value="{{ typeKey }}" id="clearingType{{ typeKey }}"
          {% if typeKey == selectedClearingType %}checked="checked"{% endif %}/>
          <label for="clearingType{{ typeKey }}">{{ typeText }}</label>
          <img src="images/info_16.png" data-toggle="tooltip"
            title="{{ 'This setting considers the selection of the licenses shown in the table below to create a clearing result.'|trans }}"
            alt="" class="info-bullet"/>
        {% endif %}
      {% endfor %}

      {% for typeKey, typeText in clearingTypes %}
        {% if typeKey == 4 %}
          <br />
          <input type="radio" class="info-bullet view-license-rc-size" name="clearingTypes" value="{{ typeKey }}" id="clearingType{{ typeKey }}"
          {% if typeKey == selectedClearingType %}checked="checked"{% endif %}/>
          <label for="clearingType{{ typeKey }}">{{ typeText }}</label>
          <img src="images/info_16.png" data-toggle="tooltip"
            title="{{ 'There is license relevant information, but this is not relevant information for the clearing of this file (for example, files that are not used at all and also not distributed)'|trans }}"
            alt="" class="info-bullet"/>
        {% endif %}
      {% endfor %}

      {% for typeKey, typeText in clearingTypes %}
        {% if typeKey == 6 %}
          <br />
          <input type="radio" class="info-bullet view-license-rc-size" name="clearingTypes" value="{{ typeKey }}" id="clearingType{{ typeKey }}"
          {% if typeKey == selectedClearingType %}checked="checked"{% endif %}/>
          <label for="clearingType{{ typeKey }}">{{ typeText }}</label>
          <img src="images/info_16.png" data-toggle="tooltip"
            title="{{ 'There may be license relevant information but this particular file should not be considered as part of actual source code (for example, transient binary files, .dll).'|trans}}"
            alt="" class="info-bullet"/>
        {% endif %}
      {% endfor %}


      <button type="button" id="toggleMoreOptions" class="btn btn-default btn-sm" style="float: right;">
        <img src="images/icons/chevron-down.png" id="toggleIcon" alt="More Options" width="12" height="12">
      </button>
      <br>

      <!-- Hidden Additional Options -->
      <div id="moreOptions" style="display: none;">
        <br>
        <input type="radio" class="info-bullet view-license-rc-size" name="clearingTypes" value="2" id="clearingType0" />
        <label for="clearingType0">{{ 'No license known'| trans }}</label>
        <img src="images/info_16.png" data-toggle="tooltip" title="{{ 'Even after review, no license relevant information can be determined'|trans }}" alt="" class="info-bullet"/>
        
        {% for typeKey, typeText in clearingTypes %}
          {% if typeKey not in [4, 5, 6] %}
            <div>
              <input type="radio" class="info-bullet view-license-rc-size" name="clearingTypes" value="{{ typeKey }}" id="clearingType{{ typeKey }}"
              {% if typeKey == selectedClearingType %}checked="checked"{% endif %}/>
              <label for="clearingType{{ typeKey }}">{{ typeText }}</label>
              <img src="images/info_16.png" data-toggle="tooltip"
                {%- if typeKey == 3 ~%}
                    title="{{ 'Mark the file for having had a look at it, but a clearing result cannot be determined at the current time'|trans }}"
                {%- elseif typeKey == 7 ~%}
                    title="{{ 'There may be license relevant information but this particular file is not distributed but used by source (for example, build config, documentation, unit test, example files).'|trans}}"
                {%- endif %}
                alt="" class="info-bullet"/>
            </div>
          {% endif %}
        {% endfor %}
      </div>
    </fieldset>

    <fieldset class="border p-2">
      <legend style="width:auto;">
        {{ 'Clearing decision scope'| trans }}
      </legend>
      <input type="checkbox" class="info-bullet view-license-rc-size" name="globalDecision" id="globalDecision"  onclick="checkIfEligibleForGlobalDecision()" {% if selectedClearingScope==1 %}checked{% endif %}/>
      {{ 'Apply decision to all future occurrences of this file'|trans }}
      <img data-toggle="tooltip" data-placement="left" src="images/info_16.png" title="{{ 'Based on a hash computation of the file contents, Fossology will determine a future occurrence of the same file. Then, if  the same file is part of a subsequent upload, this clearing decision will apply there as well.  Consider that this decision will impact also upload of other users. It should be checked with much care'|trans }}" alt="" class="info-bullet"/ >
    </fieldset>
  </div>
</form>

<div class="groupBox">
  {{ macro.table("licenseDecisionsTable", licenseDecisionsHeaders) }}
</div>

<div class="groupBox">

  {% if auditDenied %}
    {{ 'Sorry, you do not have write (or above) permission on this upload, thus you cannot change the license of this
    file.
    '| trans }}
  {% else %}
    <button type="button" data-toggle="modal" data-target="#userModal" class="btn btn-default btn-sm" onclick="openUserDecisionModal();">
      {{ 'User Decision ...'| trans }}
    </button><img src="images/info_16.png" data-toggle="tooltip" title="{{ 'Add manually a license that is not found by scanners or bulk'|trans }}" alt="" class="info-bullet"/>
    &nbsp;
    <button type="button" data-toggle="modal" data-backdrop="false" data-target="#bulkModal" class="btn btn-default btn-sm" onclick="openBulkModal();">
      {{ 'Bulk Recognition ...'| trans }}
    </button><img src="images/info_16.png" data-toggle="tooltip" title="{{ 'Adding or removing a license based on a text fragment that is searched for across the relevant files'|trans }}" alt="" class="info-bullet"/>
    &nbsp;
    <button type="button" data-toggle="modal" data-target="#ClearingHistoryDataModal" class="btn btn-default btn-sm" onclick="openClearingHistoryDataModal();">
      {{ 'Clearing History ...'| trans }}
    </button><img src="images/info_16.png" data-toggle="tooltip" title="{{ 'View the clearing history for this file: The table will show which user added or removed license results for this particular file in order to create a clearing decision. Clearing decisions are created when the user clicks on the button "Submit" or on the go next and go previous buttons'|trans }}" alt="" class="info-bullet"/>
    &nbsp;
    <br/>
    <span id="bulkIdResult" name="bulkIdResult"></span>
    <div style="padding-top: 10px;">
    <!-- The user Modal -->
    <div class="modal" id="userModal" tabindex="-1" role="dialog" aria-labelledby="userModalLabel" aria-hidden="true" data-backdrop="false">
      <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
          <!-- Modal Header -->
          <div class="modal-header">
            <h4 class="modal-title">Add a New License</h4>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <!-- Modal body -->
          <div class="modal-body" style="max-height:300px;overflow:auto;">
            <div style="padding-bottom: 10px">
              {{ macro.table("licenseSelectionTable") }}
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- The clearing history Modal -->
    <div class="modal" id="ClearingHistoryDataModal" tabindex="-1" role="dialog" aria-labelledby="ClearingHistoryDataModalLabel" aria-hidden="true" data-backdrop="false">
      <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
          <!-- Modal Header -->
          <div class="modal-header">
            <h4 class="modal-title">Clearing History</h4>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <!-- Modal body -->
          <div class="modal-body">
            <div style="padding-bottom: 10px;">
              {{ macro.table("ClearingHistoryDataModalTable") }}
            </div>
          </div>
        </div>
      </div>
    </div>

      {% include 'ui-clearing-view_bulk.html.twig' %}
    </div>
  {% endif %}

</div>
<div class="groupBox" id="bulkHistory" {% if not bulkHistory %}hidden{% endif %}>

<h3>
{{ 'Bulk History'| trans }}
</h3>

<div class="scrollable2">
{% include 'bulk-history.html.twig' %}
</div>
</div>

<script>
document.addEventListener("DOMContentLoaded", function () {
    var moreOptions = document.getElementById("moreOptions");
    var icon = document.getElementById("toggleIcon");

    var hiddenOptionSelected = moreOptions.querySelector('input[type="radio"]:checked');
    if (hiddenOptionSelected) {
      moreOptions.style.display = "block"; // or "unset" if that suits your layout
      icon.style.transform = "rotate(180deg)";
    } else {
      moreOptions.style.display = "none";
      icon.style.transform = "rotate(0deg)";
    }

    document.getElementById("toggleMoreOptions").addEventListener("click", function () {
        if (moreOptions.style.display === "none" || moreOptions.style.display === "") {
            moreOptions.style.display = "unset";
            icon.style.transform = "rotate(180deg)";
        } else {
            moreOptions.style.display = "none";
            icon.style.transform = "rotate(0deg)";
        }
    });
});
</script>
